#include<bits/stdc++.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef struct LNode{
	int data;
	LNode *next;	
}LNode, *LinkList; 
Status Init(LinkList &L)
{
	L = new LNode;
	if(!L) return ERROR;
	L->next = NULL;
	return OK;
}
Status Create(LinkList &L, int n, int m)
{
	LNode *t = L;
	for(int i = 0; i < m; i ++)
	{
		LNode *p = new LNode;
		if(!p) return ERROR;
		cin >> p->data;
		p->next = t->next;
		t->next = p;
		t = p;
	}
	LNode *t1 = t;
	if(n - m == 0)
		t->next = NULL;
	else
	{
		for(int i = 0; i < n - m; i ++)
		{
			LNode *p = new LNode;
			if(!p) return ERROR;
			cin >> p->data;
			p->next = t->next;
			t->next = p;
			t = p;
		}
		t->next = t1;	
	}
	
	
	return OK;
}
LNode *FindLoopStart(LinkList head)
{
	/**************Begin**************/
    if (head == nullptr || head->next == nullptr) 
        return nullptr;
    
    LNode *slow = head->next;
    LNode *fast = head->next;
    bool hasCycle = false;
    
    while (fast != nullptr && fast->next != nullptr) {
        slow = slow->next;
        fast = fast->next->next;
        if (slow == fast) {
            hasCycle = true;
            break;
        }
    }
    
    if (!hasCycle) 
        return nullptr;
    
    slow = head->next;
    while (slow != fast) {
        slow = slow->next;
        fast = fast->next;
    }
    return slow;
    /**************End*****************/
}
void Show(LinkList L)
{
	LNode *p = L->next;
	while(p)
	{
		cout << p->data << ' ';
		p = p->next;
	}
	cout << endl;
}
int main()
{
	LinkList L;
	Init(L);
	
	int n, m;
	cin >> n >> m;
	
	Create(L, n, m);
	LNode *p = FindLoopStart(L);
	if(p) cout << "有环" << endl;
	else cout << "无环" << endl;
	 
	return 0;
}